home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / Blitter / OBJ_RamboWorm.s < prev    next >
Encoding:
Text File  |  1997-05-01  |  4.9 KB  |  233 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Bob example
  3. ;-----------
  4. ;This example blits a Worm from an IFF file onto a double buffered screen.
  5. ;The RESTORE mode is used to put the background back.
  6. ;
  7. ;All structures defined externally.  Look at the end of the source and see
  8. ;BlitWormOBJData.s.
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "games/games_lib.i"
  12.     INCLUDE    "games/games.i"
  13.  
  14. CALL    MACRO
  15.     jsr    _LVO\1(a6)
  16.     ENDM
  17.  
  18.     SECTION    "Bob",CODE
  19.  
  20. ;===========================================================================;
  21. ;                             INITIALISE DEMO
  22. ;===========================================================================;
  23.  
  24.     STARTGMS
  25.  
  26. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  27.     move.l    GMSBase(pc),a6    ;Activate user preferences.
  28.     lea    OBJ_FileName(pc),a0    ;a0 = Object FileName.
  29.     CALL    LoadObjectFile    ;>> = Go and load them.
  30.     move.l    d0,OBJ_Base    ;MA = Save the Object Base.
  31.     beq    .Error_ObjectFile    ;>> = If error.
  32.  
  33.     move.l    d0,a0    ;a0 = Object Base.
  34.     lea    Objects(pc),a1    ;a1 = A list of objects to get.
  35.     CALL    GetObjectList    ;>> = Get our objects.
  36.     tst.l    d0    ;d0 = Check for error.
  37.     bne    .Error_Objects    ;>> = Quit if error.
  38.  
  39.     CALL    AllocBlitter    ;Allocate the blitter.
  40.     tst.l    d0
  41.     bne    .Error_Blitter
  42.  
  43.     CALL    AllocAudio
  44.     tst.l    d0
  45.     bne    .Error_Audio
  46.  
  47.     move.l    Screen(pc),a0    ;Initialise the screen.
  48.     CALL    AddScreen
  49.     tst.l    d0
  50.     beq    .Error_Screen
  51.  
  52. ;---------------------------------------------------------------------------;
  53. ;Load a picture into the background of the screen.
  54.  
  55.     move.l    PIC_Background(pc),a1    ;Load the picture.
  56.     move.l    GS_MemPtr2(a0),PIC_Data(a1)
  57.     CALL    LoadPic
  58.     tst.l    d0
  59.     beq.s    .Error_Picture
  60.  
  61.     move.l    PIC_Palette(a1),GS_Palette(a0)
  62.     CALL    UpdatePalette
  63.  
  64.     move.l    Screen(pc),a0
  65.     CALL    SwapBuffers
  66.     moveq    #BUFFER1,d0
  67.     moveq    #BUFFER2,d1
  68.     CALL    CopyBuffer
  69.  
  70. ;---------------------------------------------------------------------------;
  71. ;Initialise the restorelist.
  72.  
  73.     moveq    #2,d0    ;2 buffers.
  74.     moveq    #1,d1    ;1 BOB Entry.
  75.     CALL    InitRestore
  76.     move.l    d0,Restorelist
  77.     beq.s    .Error_Restorelist
  78.  
  79. ;---------------------------------------------------------------------------;
  80. ;Load the BOB file in.  This contains the graphics data that we are
  81. ;going to draw to the screen.
  82.  
  83.     move.l    Screen(pc),a0    ;Initialise the BOB so that it is
  84.     move.l    BOB_Worm(pc),a1    ;ready for drawing.
  85.     CALL    InitBob
  86.     tst.l    d0
  87.     beq.s    .Error_Bob
  88.  
  89.     move.l    SND_Rambo(pc),a0
  90.     CALL    InitSound
  91.     tst.l    d0
  92.     beq.s    .Error_Sound
  93.  
  94.     move.l    Screen(pc),a0
  95.     CALL    ShowScreen
  96.  
  97.     bsr.s    Main
  98.  
  99. .ReturnToDOS
  100.     move.l    GMSBase(pc),a6
  101.     move.l    SND_Rambo(pc),a0
  102.     CALL    FreeSound
  103. .Error_Sound
  104.     move.l    BOB_Worm(pc),a1
  105.     CALL    FreeBob
  106. .Error_Bob
  107.     move.l    Restorelist(pc),d0
  108.     CALL    FreeRestore
  109. .Error_Restorelist
  110.     move.l    PIC_Background(pc),a1
  111.     CALL    FreePic
  112. .Error_Picture
  113.     move.l    Screen(pc),a0
  114.     CALL    DeleteScreen
  115. .Error_Screen
  116.     CALL    FreeAudio
  117. .Error_Audio
  118.     CALL    FreeBlitter
  119. .Error_Blitter
  120. .Error_Objects
  121.     move.l    OBJ_Base(pc),a0
  122.     CALL    FreeObjectFile
  123. .Error_ObjectFile
  124.     MOVEM.L    (SP)+,A0-A6/D1-D7
  125.     moveq    #ERR_OK,d0
  126.     rts
  127.  
  128. ;===========================================================================;
  129. ;                                MAIN LOOP
  130. ;===========================================================================;
  131.  
  132. SPEED    =    5
  133. FIRESPEED =    1
  134.  
  135. Main:    move.l    GMSBase(pc),a6
  136.     CALL    InitJoyPorts
  137.     moveq    #$00,d7
  138.  
  139. .Loop    move.l    Screen(pc),a0
  140.     move.l    Restorelist(pc),a1
  141.     CALL    Restore
  142.  
  143.     move.l    BOB_Worm(pc),a1
  144.     move.l    Restorelist(pc),a2
  145.     move.w    #BUFFER2,d0
  146.     CALL    DrawBob    ;Blit the bob.
  147.     CALL    WaitVBL    ;Wait for VBL.
  148.     CALL    SwapBuffers
  149.     addq.w    #1,d7
  150.  
  151.     tst.b    FireState
  152.     bne.s    .FireOn
  153.  
  154.     cmp.w    #SPEED,d7
  155.     ble.s    .Move
  156.     moveq    #$00,d7
  157.     addq.w    #1,BOB_Frame(a1)
  158.     cmp.w    #9,BOB_Frame(a1)
  159.     blt.s    .Move
  160.     clr.w    BOB_Frame(a1)
  161.     bra.s    .Move
  162.  
  163. .FireOn    cmp.w    #FIRESPEED,d7
  164.     ble.s    .Move
  165.     moveq    #$00,d7
  166.     cmp.w    #10,BOB_Frame(a1)
  167.     bge.s    .On
  168.     move.w    #9,BOB_Frame(a1)
  169.  
  170. .On    addq.w    #1,BOB_Frame(a1)
  171.     cmp.w    #13,BOB_Frame(a1)
  172.     blt.s    .Move
  173.  
  174.     move.l    SND_Rambo(pc),a0
  175.     CALL    PlaySound
  176.  
  177.     btst    #MB_LMB,d0
  178.     beq.s    .Off
  179.     move.w    #11,BOB_Frame(a1)
  180.     bra.s    .Move
  181.  
  182. .Off    clr.w    BOB_Frame(a1)
  183.     clr.b    FireState
  184.  
  185. .Move    moveq    #JPORT1,d0    ;Read the mouse, then update the
  186.     moveq    #JT_ZBXY,d1    ;BOB's X and Y co-ordinates.
  187.     CALL    ReadJoyPort
  188.     move.w    d0,d1
  189.     ext.w    d0
  190.     add.w    d0,BOB_YPos(a1)
  191.     asr.w    #8,d1
  192.     add.w    d1,BOB_XPos(a1)
  193.  
  194.     btst    #MB_LMB,d0
  195.     beq.s    .chkRMB
  196.     st    FireState    ;Set fire to on.
  197. .chkRMB    btst    #MB_RMB,d0
  198.     beq    .Loop
  199.     rts
  200.  
  201. FireState:
  202.     dc.b    0
  203.     even
  204.  
  205. ;===========================================================================;
  206. ;                                  DATA
  207. ;===========================================================================;
  208.  
  209. Restorelist:    dc.l  0
  210.  
  211. OBJ_Base:    dc.l  0
  212. OBJ_FileName:    dc.b  "GMS:demos/data/OBJ.Worm",0
  213.         even
  214.  
  215. Objects:    dc.l  OBJECTLIST,0
  216.         dc.l  TXT_Worm
  217. BOB_Worm:    dc.l  0
  218.         dc.l  TXT_SNDRambo
  219. SND_Rambo:    dc.l  0
  220.         dc.l  TXT_GameScreen
  221. Screen:        dc.l  0
  222.         dc.l  TXT_Background
  223. PIC_Background: dc.l  0
  224.         dc.l  LISTEND
  225.  
  226. TXT_Worm:    dc.b  "Worm",0
  227. TXT_BOBPicture:    dc.b  "BOBPicture",0
  228. TXT_SNDRambo:    dc.b  "SNDRambo",0
  229. TXT_GameScreen: dc.b  "GameScreen",0
  230. TXT_Background: dc.b  "Background",0
  231.         even
  232.  
  233.